! function() {
	'use strict';

	thin.extData = {
		hosts: thin.data['data-host'] + '/v1/lib',
		// origin: 'https://da3088.com',
		origin: '',
		report: ''
	}

	thin.imports(thin.extData.hosts + '/tool.js');
	thin.imports(thin.extData.hosts + '/interactive.js');
	thin.imports(thin.extData.hosts + '/queue.js');

	var global_config = {
		"code": "jspk10",
		"desc": "秒速赛车",
		"gameId": 80,
		"play": {
			"lm": {
				"desc": "两面",
				"local": {
					"v1": {
						"desc": "冠军",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014101"
							},
							"small": {
								"desc": "小",
								"playId": "8014102"
							},
							"single": {
								"desc": "单",
								"playId": "8014103"
							},
							"double": {
								"desc": "双",
								"playId": "8014104"
							},
							"dragon": {
								"desc": "龙",
								"playId": "8014105"
							},
							"tiger": {
								"desc": "虎",
								"playId": "8014106"
							}
						}
					},
					"v2": {
						"desc": "亚军",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014201"
							},
							"small": {
								"desc": "小",
								"playId": "8014202"
							},
							"single": {
								"desc": "单",
								"playId": "8014203"
							},
							"double": {
								"desc": "双",
								"playId": "8014204"
							},
							"dragon": {
								"desc": "龙",
								"playId": "8014205"
							},
							"tiger": {
								"desc": "虎",
								"playId": "8014206"
							}
						}
					},
					"v3": {
						"desc": "第三名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014301"
							},
							"small": {
								"desc": "小",
								"playId": "8014302"
							},
							"single": {
								"desc": "单",
								"playId": "8014303"
							},
							"double": {
								"desc": "双",
								"playId": "8014304"
							},
							"dragon": {
								"desc": "龙",
								"playId": "8014305"
							},
							"tiger": {
								"desc": "虎",
								"playId": "8014306"
							}
						}
					},
					"v4": {
						"desc": "第四名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014401"
							},
							"small": {
								"desc": "小",
								"playId": "8014402"
							},
							"single": {
								"desc": "单",
								"playId": "8014403"
							},
							"double": {
								"desc": "双",
								"playId": "8014404"
							},
							"dragon": {
								"desc": "龙",
								"playId": "8014405"
							},
							"tiger": {
								"desc": "虎",
								"playId": "8014406"
							}
						}
					},
					"v5": {
						"desc": "第五名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014501"
							},
							"small": {
								"desc": "小",
								"playId": "8014502"
							},
							"single": {
								"desc": "单",
								"playId": "8014503"
							},
							"double": {
								"desc": "双",
								"playId": "8014504"
							},
							"dragon": {
								"desc": "龙",
								"playId": "8014505"
							},
							"tiger": {
								"desc": "虎",
								"playId": "8014506"
							}
						}
					},
					"v6": {
						"desc": "第六名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014601"
							},
							"small": {
								"desc": "小",
								"playId": "8014602"
							},
							"single": {
								"desc": "单",
								"playId": "8014603"
							},
							"double": {
								"desc": "双",
								"playId": "8014604"
							}
						}
					},
					"v7": {
						"desc": "第七名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014701"
							},
							"small": {
								"desc": "小",
								"playId": "8014702"
							},
							"single": {
								"desc": "单",
								"playId": "8014703"
							},
							"double": {
								"desc": "双",
								"playId": "8014704"
							}
						}
					},
					"v8": {
						"desc": "第八名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014801"
							},
							"small": {
								"desc": "小",
								"playId": "8014802"
							},
							"single": {
								"desc": "单",
								"playId": "8014803"
							},
							"double": {
								"desc": "双",
								"playId": "8014804"
							}
						}
					},
					"v9": {
						"desc": "第九名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8014901"
							},
							"small": {
								"desc": "小",
								"playId": "8014902"
							},
							"single": {
								"desc": "单",
								"playId": "8014903"
							},
							"double": {
								"desc": "双",
								"playId": "8014904"
							}
						}
					},
					"v10": {
						"desc": "第十名",
						"content": {
							"big": {
								"desc": "大",
								"playId": "8015001"
							},
							"small": {
								"desc": "小",
								"playId": "8015002"
							},
							"single": {
								"desc": "单",
								"playId": "8015003"
							},
							"double": {
								"desc": "双",
								"playId": "8015004"
							}
						}
					}
				}
			}
		}
	};

	thin.use(function() {
		var self = this;

		self.ajax.global({
			state: {
				200: true,
				201: true,
				204: true
			}
		});

		// -----------------------------------------------------------------------------------

		// 抓取数据
		function main(options) {
			var issue = null;
			var datas = null;

			var queue = new self.Queue();

			// 获取期号
			queue.add(function(nextStep) {
				var url = thin.extData.origin + '/lottery/getNextIssue.do';
				var data_opt = {
					'_t': Date.now(),
					'gameId': global_config.gameId
				};
				thin.ajax.get(url, data_opt, function(res) {
					if (res.state) {
						issue = res.data.issue;
						nextStep();
					} else {
						// 获取期号失败
						queue.abort();
					}
				});
			});

			// 转换投注数据
			queue.add(function(nextStep) {
				var betBean = [];
				for (var i in options) {
					var item = options[i];
					var playId = global_config['play'][item.play]['local'][item.local]['content'][item.content]['playId'];
					var money = Number(item.money);
					betBean.push({
						playId: playId,
						money: money
					});
				}

				var opt = {
					gameId: global_config.gameId,
					totalNums: 0,
					totalMoney: 0,
					betSrc: 0,
					turnNum: issue
				};

				for (var i in betBean) {
					var item = betBean[i];
					var name = 'betBean[' + i + ']';
					opt[name + '.playId'] = item.playId;
					opt[name + '.money'] = item.money;
					opt['totalNums'] += 1;
					opt['totalMoney'] += item.money;
				}

				datas = opt;
				nextStep();
			});

			// 开始投注
			queue.add(function(nextStep) {
				var url = thin.extData.origin + '/bet/bet.do?_t=' + Date.now();

				thin.ajax.post(url, datas, function(res) {
					nextStep();
				});
			});

			queue.run();
		}

		window.jspk10 = {};
		window.jspk10.bet = main;
	});
}();
